using System;
using System.IO;

namespace Gloom
{
	public class MainClass
	{
		public static void Main(string[] args)
		{
			if (args.Length > 0)
			{
				Console.WriteLine("Unrecognised arguments: Not running, displaying help instead.");
				Console.WriteLine("Gloom is an experimental bindings generator.");
				Console.WriteLine("You need to have gl.spec, gl.tm, enum.spec and enumext.spec in " + SpecsPath
				                  + ", and the Lime source files (GL.cs and that lot) in " + LimeSourcePath + ".");
				Console.WriteLine("Several of Lime's source code files are generated by this tool.");
				Console.WriteLine("It is recommended this tool is run from src/Gloom/bin/Debug/ (or Release, no "
				                  + "biggy), as this means the paths will all be fine.");
				Console.WriteLine("Gloom accepts no arguments. If an argument is passed, this help message is displayed.");
				return;
			}
			
			if (!Directory.Exists(SpecsPath) || !Directory.Exists(LimeSourcePath))
			{
				Console.WriteLine("I can't find a required path.  The path " + SpecsPath + " must contain GL spec files,"
				                  + " and " + LimeSourcePath + " should contain the Lime source code files, some of "
				                  + "which will be overwritten during the bindings generation process.");
				return;
			}
			
			Console.WriteLine("\n\n\nGloom, experimental bindings generator.");
			Console.WriteLine("Loading gl.tm...");
			GLTypePrimitiveMapper.Load();
			//GLSpec.Load();
			
			Console.WriteLine("Loading NiceFuncNames.txt...");
			GLFuncNameMunger.Load();
			
			Console.WriteLine("Processing enum.spec...");
			EnumSpecParser.ParseAndWrite(SpecFileReader.ReadAllBlocks(SpecsPath + "enum.spec"));
			
			Console.WriteLine("Processing gl.spec...");
			GLSpecParser.Parse(SpecFileReader.ReadAllBlocks(SpecsPath + "gl.spec"));
			
			Console.WriteLine("Lots of failures? I wouldn't worry too much.  Expect ~50 errors simply because some GLhalf & friends are blacklisted.");
			
			Console.WriteLine("\n\nLOTS of useful information in src/Lime/GL_translation_debug.txt and src/Lime/GL_translation_errors.txt.\n_errors shows just the key failure lines, _debug has EVERYTHING.  It's a good idea to lookup key failure lines from _error in _debug to get the full story!!");
		}
		
		public static string SpecsPath
		{
			// assuming we start in src/Gloom/bin/${Configuration}/...
			get { return "../../Specs/"; }
		}
		
		public static string LimeSourcePath
		{
			get { return "../../../Lime/"; }
		}
	}
}

